﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace ETFK
{
    public partial class eTraining : Form
    {
        public eTraining()
        {
            InitializeComponent();
        }

        public Type AnswerType { get; set; }

        public eTraining(Type type)
        {
            InitializeComponent();
            this.AnswerType = type;
        }

        private void eTraining_Load(object sender, EventArgs e)
        {
            CheckRecord.OutTextBox = this.Out;
            this.Out.Clear();
            this.Show();


            object PeopleAnswer = AnswerType.Assembly.CreateInstance(AnswerType.FullName);

            if (PeopleAnswer == null)
            {
                CheckRecord.TestError("客户答案无法创建实例！");
                return;
            }

            string fNmae = "";
            foreach (Type typ in this.GetType().Assembly.GetTypes())
            {
                Console.WriteLine(typ.Name);
                if (typ.Name.Equals(AnswerType.Name) == true)
                {
                    fNmae = typ.FullName;
                    break;
                }
            }

            if (fNmae == "")
            {
                CheckRecord.TestError("服务答案无法创建实例！");
                return;
            }
            IPractise ComputerAnswer = this.GetType().Assembly.CreateInstance(fNmae) as IPractise;

            if (ComputerAnswer == null)
            {
                CheckRecord.TestError("服务答案无法创建实例！");
                return;
            }

            CheckRecord.TestStart();

            ComputerAnswer.Check(PeopleAnswer);

            CheckRecord.TestEnd();
        }
    }
}
